<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/layouts/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>编辑字典</title>
</head>
<body>
<div class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-dict-add">
		<input type="hidden"  name="id"  value="${dict.id }">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>字典描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${dict.description }" placeholder="请输入字典描述" id="description" name="description">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>字典类型：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${dict.type }" placeholder="请输入字典类型" id="type" name="type">
			</div>
		</div>
		<div class="row cl" >
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>字典标签：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" name="label" id="label" placeholder="请输入字典标签" value="${dict.label }" class="input-text">
			</div>
		</div>
		<div class="row cl" >
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>键值：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="value" cols="" rows="" class="textarea"  placeholder="请输入标签值" onKeyUp="$.Huitextarealength(this,100)">${dict.value }</textarea>
				<p class="textarea-numberbar"><em class="textarea-length">${fn:length(dict.value)}</em>/1000</p>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button  class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
	</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctxLib }/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${ctxStatic}/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="${ctxLib }/shopUtil.js"></script>
<script type="text/javascript">
$(function(){
	$("#form-dict-add").validate({
		rules:{
			description:{
				required:true,
				checkDescrption:true
			},
			type:{
				required:true,
				checkType:true
			},
			label:{
				required:true
			},
			value:{
				required:true
			}
		},
		messages: {
			  description: {
		        	required: "请输入字典描述"
		      },
		      type: {
		        	required: "请输入字典类型"
		      },
		      label: {
		        	required: "请输入字典标签"
		      },
		      value:{
		    		required: "请输入标签值"  
		      }
	    },
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
				var formData = ShopUtil.formToJSON();
				formData.value = escape(formData.value);
				$.ajax({
                    type: 'POST',
                    url: '${ctx}/dict/edit',
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(formData),
                    dataType: 'json',
                    success: function (data) {
                        if (data.success) {
                            layer.alert('编辑成功', {
                            	  closeBtn: 0
                            }, function(){
                            	window.parent.location.reload();
                            	var index = parent.layer.getFrameIndex(window.name);
                            	parent.layer.close(index);
                           	});
                        } else {
                            layer.alert(data.message);
                        }
                    }
                });
			}
		});
	
	//自定义正则表达示验证方法  
    $.validator.addMethod("checkDescrption",function(value,element,params){  
            var checkQQ = /^[\u4E00-\u9FA5]*$/;  
            return this.optional(element)||(checkQQ.test(value));  
        },"*描述只能输入中文！");
	
    $.validator.addMethod("checkType",function(value,element,params){  
        var checkQQ = /^[a-z_]*$/;  
        return this.optional(element)||(checkQQ.test(value));  
    },"*类型只能包含字母或者下划线！");
});	
</script>
</body>
</html>